// pages/my/myInfo.js
//var card = require("../card/card.js")
Page({
  data: { 
    UserInfo: [
      
    ]
  },

  phoneCall:function(event){
      console.log(event)
      var telno = event.currentTarget.dataset.telno
      wx.makePhoneCall({
        phoneNumber: telno
        
      })
  },
  
  click_cardDetailInfo: function (event) {
    var card_id = event.currentTarget.dataset.card_id;
    console.log(card_id)
    wx.navigateTo({
      url: 'myInfo-detail/myInfo-detail?cardId=' + card_id + '&isHidden=' + false,
    })
  },

  handleImg: function(event){
    console.log(event)   
    var _url = event.target.dataset.url
    wx.previewImage({
      // current: 'String', // 当前显示图片的链接，不填则默认为 urls 的第一张
      urls: [_url],
      success: function(res){
        // success
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    })
  },
  onLoad:function(option){
    var that = this
    var openId = option.openid
    
    wx.request({

      url: 'http://localhost:8080/UserCard/findByOpenId?openId=' + openId,
      method: 'GET',


      success: function (res) {
        var userInfo = res.data.users;
        console.log(userInfo)
        if (userInfo == null) {
          var toastText = '获取数据失败' + res.data.errMsg;

        } else {
          if(userInfo[1] == null){
            that.setData({
              UserInfo: userInfo,
              isHidden: true
            })
          }else{
          that.setData({
            UserInfo: userInfo,
            isHidden: false
            })
          }
        }
      }
    })
    

  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  onShareAppMessage: function () {
    return {
      title: this.data.UserInfo[0].userName + '的名片,请惠存' ,
      path: 'pages/idCard/my/myInfo?openid=' + this.data.UserInfo[0].openId,
      success: function (res) {
        console.log(res)
        wx.getShareInfo()
      },
      fail: function () {
        console.log("转发失败")
      }
    }

  }
})